package com.prs.crm.dao.sms.impl;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Date;

import org.courser.Util;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.context.Constrains;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.sms.SmsTimerDao;
import com.prs.crm.domain.sms.SmsTimer;

public class SmsTimerDaoImpl extends BaseDaoImpl<SmsTimer> implements SmsTimerDao{
	@Override
	@SuppressWarnings("unchecked")
	public Collection<SmsTimer> getCurrentSendMsg() {
		// TODO Auto-generated method stub
		return (Collection<SmsTimer>) this.getHibernateTemplate().execute(
				new HibernateCallback() {

					@Override
					public Object doInHibernate(Session arg0)
							throws HibernateException, SQLException {
						// TODO Auto-generated method stub
						Criteria criteria = arg0.createCriteria(SmsTimer.class);
						Date current;
						try {
							current = Util.nowFullTime();							
							criteria.add(Restrictions.ge("sendTime", current));
							criteria.add(Restrictions.eq("state", Constrains.SMS_TIMER_PRE));
							return criteria.list();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}						
						return null;
					}
			
				});
	}
}
